package com.atguigu.daijia.driver.controller;

import com.atguigu.daijia.common.result.Result;
import com.atguigu.daijia.driver.service.FileService;
import com.atguigu.daijia.model.vo.driver.CosUploadVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Tag(name = "上传管理接口")
@RestController
@RequestMapping("file")
@RequiredArgsConstructor
public class FileController {

    private final FileService fileService;

    /**
     * 上传文件到腾讯云 COS
     * @param file
     * @param path
     * @return
     */
    @Operation(summary = "上传文件到腾讯云 COS")
    // @GuiguLogin
    // @PostMapping("/upload")
    public Result<String> uploadFileToCos(@RequestPart("file") MultipartFile file, @RequestParam(value = "path", defaultValue = "auth") String path) {
        CosUploadVo cosUploadVo = fileService.uploadFile(file, path);
        String showUrl = cosUploadVo.getShowUrl();
        return Result.ok(showUrl);
    }

    /**
     * 上传文件到 MinIO
     * @param file
     * @return
     */
    @Operation(summary = "上传文件到 MinIO")
    // @GuiguLogin
    @PostMapping("/upload")
    public Result<String> uploadToMinIO(@RequestPart("file") MultipartFile file) {
        String url = fileService.uploadToMinIO(file);
        return Result.ok(url);
    }


}
